package com.eva.androidlibrary.widget.tabhost;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

/**
 * Class description
 *
 * @author GUXIA318
 * @date 2015-09-16 13:56
 */
public abstract class FragmentTabHostLayoutAdapter extends TabHostLayoutAdapter {

    private int mContainerId;
    private FragmentManager mFragmentManager;

    public FragmentTabHostLayoutAdapter(int containerId, FragmentManager fm) {
        this.mContainerId = containerId;
        this.mFragmentManager = fm;
    }

    public Fragment getFragment(int position) {
        Fragment f = mFragmentManager.findFragmentByTag(getFragmentTag(position));
        if (f == null) {
            f = getFragmentInstance(position);
        }
        return f;
    }

    public abstract Fragment getFragmentInstance(int position);

    public FragmentManager getFragmentManager() {
        return mFragmentManager;
    }

    public int getContainerView() {
        return mContainerId;
    }

    public String getFragmentTag(int position) {
        return String.valueOf(position);
    }

}
